package cn.zy.shardbatisdemo.strategy;

/**
 * @author zhagnying
 * @description
 * @date 2019/9/11
 */

import cn.zy.shardbatisdemo.service.TablesService;
import cn.zy.shardbatisdemo.tools.SpringContextAware;
import com.google.code.shardbatis.strategy.ShardStrategy;

import java.util.Map;

/**
 * 继承ShardStrategy类
 */
public class MyShardStrategy implements ShardStrategy {

    @Override
    public String getTargetTableName(String baseTableName, Object params, String mapperId) {
//        String id = ((Map<String, String>)params).get("id");//解析参数，获取需要的参数
        String id = (String) params;//解析参数，获取需要的参数
        TablesService tablesService = SpringContextAware.getBean("tablesService");//获取对应的Bean
        return tablesService.getTableName(id);
    }
}

